// pages/mine/index.js
var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        is_notary: 0,
        is_vx: 0,
        user_login: false, //是否登录
        userInfo: {
            avatarUrl: '', //头像地址
            nickName: '你懂得', //授权昵称
            full_name: '李阳', //姓名
            telephone: '159****2262', //注册电话
            identity: 0, //身份 0普通1员工
            attest: 0, //认证状态
        },
        showActionSheet: false,
        button: [{
                text: "取消",
                type: "primary",
                plain: true
            },
            {
                text: "确定",
                type: "primary",
                plain: false
            }
        ]
    },
    //页面跳转
    to_url: function (e) {
        let page = Number(e.currentTarget.dataset.type);
        if (this.data.user_login == false && page !== 3) {
            wx.showModal({
                title: '登陆提醒',
                content: '尚未登录，请登录后查看相关内容',
                confirmText: '去登陆',
                confirmColor: '#3a77ef',
                success(res) {
                    if (res.confirm) { //确认
                        wx.reLaunch({ //跳转登录
                            url: '/pages/login/index'
                        })
                    } else if (res.cancel) { //取消

                    }
                }
            })
            return;
        }
        if (page == 0) { //进行中
            wx.navigateTo({
                url: '/pages/order/index?tab=0&order_status=0'
            })
        } else if (page == 1) { //已完成
            wx.navigateTo({
                url: '/pages/order/index?tab=1&order_status=1'
            })
        } else if (page == 2) { //个人信息
            wx.navigateTo({
                url: '/pages/perfect/pages/oneself/index'
            })
        } else if (page == 3) { //关于我们（单页）
            wx.navigateTo({
                url: '/pages/perfect/pages/single/index?id='
            })
        } else if (page == 4) { //关于我们（单页）
            wx.navigateTo({
                url: '/pages/forensics/pages/v/index?is_notary=' + this.data.is_notary
            })
        }
    },
    //登录跳转
    to_login: function (e) {
        wx.reLaunch({
            url: '/pages/login/index',
        })
    },
    //技术支持跳转
    jump_applet(e) {
        wx.navigateToMiniProgram({
            appId: 'wx207739c490fbf5af',
            path: 'pages/card/index',
            extraData: {
                link_source: '智享库'
            },
            envVersion: 'release',
            success(res) {
                // 打开成功
            }
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        var hotline = wx.getStorageSync('hotline');
        let is_vx = wx.getStorageSync('is_vx');
        this.setData({
            is_vx: is_vx,
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: async function () {
        var user_login = getApp().checkIsLogin(); +
        console.log(user_login)
        let is_notary = wx.getStorageSync('is_notary');
        this.setData({
            user_login: user_login,
            is_notary: is_notary,
        })
        console.log('公证员id' + is_notary);
        if (is_notary > 0) {

            //获取公证员的信息
            let notary_msg = wx.getStorageSync('notary_msg');
            let notary_userInfo = {
                headimg: notary_msg.headimg, //头像地址
                // nickname: notary_msg.username, //授权昵称
                nickname: notary_msg.nickname, //姓名
                phone: notary_msg.contact_phone, //注册电话
                identity: 1, //身份 0普通1员工
                attest: 0, //认证状态   
            }
            if (typeof notary_msg.contact_phone != "undefined" && notary_msg.contact_phone != "") {
                this.setData({
                    user_login: true,
                })
            }
            this.setData({
                userInfo: notary_userInfo,
            });
        } else {
            let params = {}
            getApp()._post_form('data/api.auth.center/get', params, (result) => {
                this.setData({
                    userInfo: result.data,
                });
            })
            // var data = await getApp().getMember(); //获取登录用户详细信息
            // console.log(data)
            // this.setData({
            //     userInfo: data,
            // });
        }

    },
    //获取微信用户手机号方法  

    getPhoneNumber(e) {
        console.log(e.detail.code)
        console.log(e.detail.errMsg)
        console.log(e.detail.iv)
        let params = {}
        params.code = e.detail.code;

        getApp()._post_form('data/api.auth.order/get_phone', params, (result) => {
            console.log(result.data);
            this.setData({
                'userInfo.phone': result.data
            })
            wx.showToast({
                title: '授权成功',
                icon: 'none',
                mask: false,
            });
        })

    },
    openActionSheet: function (e) {
        this.setData({
            showActionSheet: true
        })
    },
    modal_click: function (e) {
        console.log(e.detail.index);
        let index = e.detail.index
        if(index == 0){
            this.setData({
                showActionSheet: false
            })
        }else{
            wx.clearStorage();
            wx.showToast({
                title: '退出成功',
                icon: 'success',
                mask: true,
                duration: 1500
            })
            setTimeout(() => {
                wx.reLaunch({
                    url: '/pages/login/index',
                })
            }, 1500)
        }
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    }
})